package com.ruoyi.carShopService.service.impl;

import com.ruoyi.carShopService.mapper.LoginMapper;
import com.ruoyi.carShopService.service.LoginService;
import com.ruoyi.carShopService.util.SmsUtil;
import com.ruoyi.system.api.domain.CarMerchantPrincipal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.time.temporal.Temporal;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author yang
 * @version 1.0
 * @data 2024/9/12 15:56
 */
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private LoginMapper loginMapper;

    // 生成验证码，发送短信，存入redis
    @Override
    public Map createSms(String phoneNumber) {
        Map<String, String> map = new HashMap<>();
        String code = SmsUtil.createCode();
//        SmsUtil.send(phoneNumber, code);
        map.put(phoneNumber,code);
        // 存入redis
        redisTemplate.opsForValue().set(phoneNumber, code,100, TimeUnit.MINUTES);
        return map;
    }

    @Override
    public CarMerchantPrincipal selectByPhoneNumber(String phoneNumber) {
        return loginMapper.selectByPhoneNumber(phoneNumber);
    }

    // 通过id查询用户信息
    @Override
    public CarMerchantPrincipal selectByMerchantId(String mpId) {
        return loginMapper.selectByMerchantId(mpId);
    }


}
